Make sure the tempfile exists before closing it.