using context manager for all temporary file operations