The output from -x goes to stderr, not stdout. But even that can be a problem -- plenty of scripts will have functional dependencies on the content of stderr, and its kind of messy to have the debug and stderr streams mixed together in some cases.
Bash versions > 4.1 do offer a different solution: the BASH_XTRACEFD environment variable allows you to specify a file descriptor which will be used to send the debug stream to. This can be a file or pipe or any other unix-y goodness you like.
# Use FD 19 to capture the debug stream caused by "set -x":
# Tell bash about it (there's nothing special about 19, its arbitrary)
# turn on the debug stream:
# run some commands:
echo "Well, that was fun."
# Close the output:
# See what we got:
With a bit more fiddling, you can do other things -- like doing a 'tee' on the stdout and/or stdin streams, and interleave those with the debug output, so your log is more complete. For more details on this, see https://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself.
The big advantage of this approach over alternatives is that you're not risking changes to the behavior of your script by injecting debug output into stdout or stderr.