flush file when writing to database