Closing output file in generator