Close file properly