rework tempfile handling to explicitly close a filehanle - assigning it to undef...