Close file to prevent memory leak