Linux Command - tee
The linux command tee allows you to write to both standard output and a file. It reads from standard input.
Print output and also write to output.txt:
ps -ef | tee output.txt
Append instead of overwrite:
ps -ef | tee -a output.txt