I am using Mule Studio to export database results into a .csv file. My flow is as follows

I can connect to the database fine, and use the results in the data mapper. However, when I go to export the results it writes to the file I specified but only adds one row, which is then overwritten by the next row and so forth.

My question is how do I ensure new rows are added to the .csv file from the SQL result? Also, I do not know how to add headings to the .csv file, so the data makes no sense.

My XML config is below

