Changed writeNode method to write parent pointer for root.