Use `with open() as` statements within generate_file()