creating tree and writing to file