Postpone tempfile closing to avoid file GC before copy into container