consume a stream of objects and save them to a file