I couldn't see how the tree could possibly handle loops.
The algorithm uses "loop-erased" random walks.
It starts at a node that isn't in the tree and randomly walks.
If it hits itself while randomly walking (remember it isn't part of the tree yet), it erases the loop that it created and continues walking from that node again.
If the walk hits the tree, connect the walked path to the tree, pick another node and start again.
The same code that generates the walls inside the maze must also generate the walls on the edge of the maze - you can't just put a solid border and declare the corners the start and end.
(Well you can, but then there's not a single path.)