Minimise code in `with tempfile` block