See the documentation for open and print, and How do I write to a file?.
In reply to Re: How to save the output result in file by hdb in thread How to save the output result in file by rammohan