tl;dr: Use redirection, > and >> etc.
>
>>
1command > file.xt # redirect stdout 2command 2> file.txt # redirect stderr 3command &> file.txt # redirect both stdout and stderr