I haven't read the whole script, but I did notice that you used the file name test.py - I also tried this and it turns out that it won't work.
Use some other file name and you might get better results.
An alternative to writing and reading from file would be to store the dictionary in a class. I do this all the time and this sort of thing can be found in the modules I've written for you also. (There is most of the time a some array defined right after the class definition, making the name a class variable.)
It would also be possible to store a dictionary as a field of an instance of a class. So each "store" would be a new instance of that class then, with its own inventory dictionary.
But for any sort of real use of your script you should of course be able to store and retrieve the data. But you don't need to learn how to do this just to be able to mod CivIV. Because, as God-Emperor pointed out - and as I've already solved this for you within you mod's Python content - the game has its own file I/O procedures. You only need to be able to tap into that.

An alternative to writing and reading from file would be to store the dictionary in a class. I do this all the time and this sort of thing can be found in the modules I've written for you also. (There is most of the time a some array defined right after the class definition, making the name a class variable.)
It would also be possible to store a dictionary as a field of an instance of a class. So each "store" would be a new instance of that class then, with its own inventory dictionary.
But for any sort of real use of your script you should of course be able to store and retrieve the data. But you don't need to learn how to do this just to be able to mod CivIV. Because, as God-Emperor pointed out - and as I've already solved this for you within you mod's Python content - the game has its own file I/O procedures. You only need to be able to tap into that.