Although I believe perrin has answered your immediate problem already in this thread, I think that it may be worthwhile to direct your attention to this node on using temporary files in Perl written by myself previously. This discussion highlights a number of issues with regards to using temporary files in general and how to implement secure usage of temporary files using the POSIX::tmpnam or IO::File::new_tmpfile functions.