write database to file