See this Gist for the full source.
This python script generates a random tree (as in this example), and saves it in a CSV-compliant file (without header). Each line of the file represents a leaf node using a tuple serialization of its prefix, that indicate the path from the root node to the leaf.
Usage (ipython):
run generate_random_tree.py
generate('tree.csv', 6, 8) # filename, maximum depth, maximum branching factor
An example tree containing 85 leaves is included.
The serialization format is not common for trees, but useful in our study about fractal treemaps (also known as jigsaw treemaps). A better, more generic format for saving trees is, for example, the Newick format.