Notes API: write_notes_tree(): Store the notes tree in the database