Fix creation and deletion of tempfile