fix insecure tempfiles

- modernizes all the tempfile code as well