use File::MkTemp; $dir = '.'; # directory to create file in $fh = mkstemp('tempXXXXXX',$dir); print $fh "stuff"; $fh->close;