My first impression is that you tried to close DH with close instead of closedir and perhaps this is why the resource (the directory) is busy and can't then accept the renames.
Good catch! This is the most reasonable guess so far. I didn't know that failing to closedir may have this side effect. But then I rarely explicitly myself.