Ensure file handle is closed by using with statement