Fix a minor logical error in header write

Root node should be written before header write
Add test for btree header read/write