To do so, simply send the output of the script to a file like this:
~/Library/Mobile\ Documents/com\~apple\~TextEdit/Documents/filename.txt
So, to save a list of a directory's contents, you'd use this:
ls -al > ~/Library/Mobile\ Documents/com\~apple\~TextEdit/Documents/list.txt
That saves a file called list.txt in TextEdit's Documents folder. Look inside the ~/Library/Mobile\ Documents folder for the paths to other apps you have that can use iCloud. Each folder in the Mobile Documents folder has a Documents sub-folder. Depending on the app, you may be able to access the files on another Mac or on iOS.

