I would like to create a temp file, write to the file-handle then call an external program with the filename.
The problem is I would normally want to close the file after writing to it and before calling the external program, but if I understand correctly close-ing a tempfile() causes it to be removed.
So what is the solution here?
Write to the temp file with buffering turned off. Call the external program before you close the file in the Perl script, and the external program will be able to read everything you have written.