How can I change the output directory?

You can use the option --output-directory=NAME to specify an alternative location for all output files.

For example, you would run

pdflatex --output-directory=/tmp mydoc.tex

to create the output file /tmp/mydoc.pdf.