Ordering taxonomy output in this function

get_ancestors() returns an array with the parent first, then the grandparent, etc. What you need to do change get_ancestors() to array_reverse( get_ancestors() ), so that you have the level of the parents descends, instead of ascending.