Transfers data from a database to a .csv file