Close file in helper method