How to export table data into to a text (.txt) file

Hello, I need to create a text file from a script. How to export table data into to a text (.txt) file?