Make sure files get closed if stop iterating before end of file