I have used >> like os.system("the_command >> the_file_you_want_the_data_in") or in your case os.system("pwd >> logfile.txt")