Nitrox,
You mentioned that you are trying to make this work cross platform, this creates a problem. In Unix, it is possible to delete a file that is locked. I would suggest you use $$ and
Proc::ProcessTable. It says Unix, but it does have a port to Cygwin.
Cheers - L~R