If your script is creating temporary files and directories when it is run, take a look at File::Temp. It gives you control over the creation/deletion of temporary files and directories.
davidj
Comment on Re: delete newly created files and directories leaving old ones