Writing to a plain file is probably faster. Talking to a database has some overhead like passing data through a network/socket connection, parsing and interpreting SQL statements (although excessive parsing can be avoided by using a prepared statement). Also there's additional overhead in the underlying file structure of databases, and possible the index overhead.