Ensure file reading was closed properly