use constant TEMP_FILENAME_TEMPLATE=>File::Spec::Unix::tmpdir() . "mytmp_XXXXXXX'; my ($tempfh, $tempFilename) = File::Temp::tempfile( TEMP_FILENAME_TEMPLATE, UNLINK=>1); # Write the job text to the temp file. print $tempfh $resultJobText; # Close the file (flush) close($tempfh);