Why does 'set -x' cause the terminal to dump garbage
What you're seeing here is some fancy behind-the-scenes scriptery that Apple added in OS X 10.11 to set the Terminal window title based on the current working directory. Since set -x shows what commands are being executed by bash, it also winds up showing all this normally-behind-the-scenes stuff (in painful detail). It's fairly easy to disable it, though:

unset PROMPT_COMMAND


... and then you can debug in peace, but your window title bar won't update any more. If you're done debugging and want to re-enable title bar updates, just reset the variable:

PROMPT_COMMAND=update_terminal_cwd