Write data from database to file.