Inside an interactive sqlite3 session, you sometimes want one result in a file without leaving the shell. .once redirects exactly one query.
sqlite> .mode csv
sqlite> .once users.csv
sqlite> SELECT id, email FROM users;
sqlite> SELECT 'back on screen';
back on screen
The result of the first query after .once goes to users.csv, and the next one shows on screen again. It uses whatever output mode is active, so set .mode first.
Two variations are fun. .once -x writes the next result as CSV to a temporary file and opens it in your spreadsheet app. .once -e opens it in a text editor instead. Both depend on what your system has set up to open files, so they’re more of a desktop trick than something for a server.
.output file.txt is the sibling that keeps sending everything to the file until you run .output with no name. I think that is easy to forget, and then your queries seem to print nothing. With .once that can’t happen.
The file is overwritten without a question, and the path is relative to the directory you started sqlite3 in, not the directory of the database. Use a full path when in doubt.
Further reading: Command Line Shell For SQLite