tree.write recursively calls write on children