Work wiht files

Somebody can explain to me how write the information from the game in a text file.
When I start the game from the Blender, any information write in the file,
but if start exe - file nothing occurs.

Are you using somthing along the lines of


import pickle
var="gamestuffhere"
f=open("/somefolder/somthing.txt", "w")
pickle.dump(var, f)

OR

f.write(f, var)

or do you use another method?