Only close file if it was opened internally