Write the rows in Data to Stream. This is similar to
csv_write_file/3, but can deal with data that is produced
incrementally. The example below saves all answers from the
predicate data/3 to File.
save_data(File) :-
setup_call_cleanup(
open(File, write, Out),
forall(data(C1,C2,C3),
csv_write_stream(Out, [row(C1,C2,C3)], [])),
close(Out)).