Close file properly on error