worldPosition returns an object -> Vector. This object is referring to the position of the game object. This means if you move the game object, the position is changing. As you still refer to the position (no it’s values) the Vector seems to change to. But it just reflects the changes the game object was doing.
If you want to keep the position at the time of the operation, you have to create a new position. You can do that either by explicitly crate a new Vector
position = mathutils.Vector(gameObject.worldPosition)
or by using the copy operation
position = gameObject.worldPosition().copy()
To see more details on this topic, I suggest to search for “passing by reference” and “passing by value”.
Btw. Please do not place multiple statements at a single one line, especially no “if” statements. It makes the code awful hard to read.