CHEF-4662: fix insecure tempfiles

- modernizes all the tempfile code as well