I face the same issue eight years after the question was initially asked, while using Sage Version 5.9-OSX-64bit-10.8. I am using init.sage for the first time, and every time a notebook is opened, two files are created in the .sage directory with names like init.sageCfCKee and init.sageCfCKee.py. The mulitiple copies quickly obscure everything else in the folder. Surely these files are supposed to go into the tmp or temp directories. Perhaps I have somehow corrupted my Sage setup, but for now my quick solution on my OS X Mac is to add the following two lines to the beginning of my init.sage file:
from subprocess import call
call("rm -f /Users/username/.sage/init.sage?*", shell=True)
This deletes the two offending files before any of the other init.sage commands are executed. I include a similar two lines at the beginning of other .sage files that I want to attach or load, but with "init" replaced by the name of that file. These lines can be added to any .sage file that is creating such duplicates. (Note:"/Users/username/.sage" should be replaced by the location of your own .sage file.)
WARNING: I am uncomfortable doing "rm -f" in any program, and I am concerned that deleting the two files will cause some problem, but so far I haven't noticed anything. Be careful, since if you make a typing mistake (e.g. forget the "?"), you might delete something you want to keep. Use at your own risk.
It looks like http://ask.sagemath.org/question/918/where-is-walkpy-located-after-i-attach-walksage addresses where foo.py went in the past.
In fact, that should *still* address your question if you use `attach('foo.sage')` instead of `%attach foo.sage`.
It doesn't, though your comment in the other post describes what I'm talking about (though I never had this happen in earlier versions). Both `attach foo.sage` and `attach('foo.sage')` create the two new files in the working directory.