Getting a table into a spreadsheet should not need a script. The sqlite3 shell can write CSV by itself.
sqlite3 -header -csv app.db "SELECT id, email FROM users" > users.csv
sqlite3 app.db ".import --csv --skip 1 users.csv users_copy"
-header adds the column names as the first line and -csv switches the output mode, so redirecting to a file gives a normal CSV. The second line goes the other way and loads a CSV into an existing table.
Without --skip 1 the header row would be imported as data when the table already exists. --skip needs a fairly recent SQLite (3.32 or newer), so check sqlite3 --version on older distributions.
Further reading: SQLite: Command Line Shell