Adding more knowledge here.
We can also use tee command to perform the same:
cat newfile | tee filename - rewrites/replaces the file with new content in filename
cat newfile | tee -a filename - appends to the existing content of the file in filename file