use with to ensure file-like object is always closed