Encode db as sexp and write to file.

This commit is too big, other changes: strip whitespace from title and
pass on import, refactor filename arg type so that it can be used to
enforce existing OR non-existing files.