Transferring data from database to a .csv file