Use the echo command but redirect the output
echo "Hello world!" > myfile
This creates, or replaces, the file ``myfile'' with that famous one liner. If you want to append to a file rather than replace it:-
echo "Goodbye cruel world!" » myfile