Write an iterable to a file