close file before leaving function if write fails
add first test that can do database file handling in a sandbox directory