Ok - I was wrong - it's a permissions problem but when I add this chmod code after the file is created it still gives me a file permissions error when I try to delete it.
open (SESSION, ">$temp_file") || die("$! \n");
print SESSION join(":", @temp_array) . "\n" ;
close (SESSION);
unless(...