in reply to to write string to a temp file

From the documentation:
filename

Return the name of the temporary file associated with this object (if the object was created using the "new" constructor).

$filename = $tmp->filename;
This method is called automatically when the object is used as a string.
When you use $fh in a string context, you get the filename instead. This was probably intended as a convenience...

You could try passing the filehandle as a reference, or putting it into a hash or array for which a reference is passed.