How can we execute the commands on one file in a such a way that the results will get saved in another file?
Do we have any such built in method which we can use?

Look under shelve in Python help.

you can create a class to which opens a file write data and closes a file
just invoke in your script ,use same instance as long as u want results in same file,generate seperate instance for result file #2