in reply to rmtree() is failing after some time

you can just do if(-e $tempDir) { `rm -rf $tempDir` } and you will fully benefit :)