You can redirect standard output to any file using the command >.
$ ls /Users/user/Desktop > out.txt
Using python,
os.system('ls /Users/user/Desktop > out.txt')
However, if you use python, instead of using the command, lsyou can use os.listdirto display all the files in the directory.
path = '/Users/user/Desktop'
files = os.listdir(path)
print files