Ensuring that #to_tempfile properly closes file