Basically your script doesn't work because animate mode (Auto Key) is not enabled. For example, if you take an animated object and move it up while Auto Key is off it displaces all the key values. But if Auto Key is turned on it only affects the current frame. Your script is moving the object, adding a key , moving again…
I'm in a bit of a pickle here and it's getting to me. No matter how I try I simply cannot find a way to create a keyframe for each positional change utilising iterative functions such as FOR-DO loops or WHILE-DO loops. I want to change the objects position and create a keyframe and repeat the process from the value of i=1…