Script to move object to world origin without changing z-axis position
You've lost the original locations of the objects so technically they are at the origin. In the script below I've cheated and used bpy.ops to reset the objects origins to Center of Mass.
import bpy
C = bpy.context
D = bpy.data

bpy.ops.object.select_all(action='DESELECT')

for obj in D.objects:
    obj.select_set(True)
    C.view_layer.objects.active = obj
    ### Pick one ###
    #bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
    #bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN')
    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='MEDIAN')
    obj.location[0] = 0 # x
    obj.location[1] = 0 # y
    
    C.view_layer.objects.active=None
    obj.select_set(False)

After batFINGER's suggestion I modified the code to not loop through bpy.ops calls. I also changed it to only affect selected objects. The original version would have moved cameras, lights and whatever else.
import bpy
C = bpy.context
D = bpy.data

### Pick one ###
#bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN')
#bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='MEDIAN')

for obj in  C.selected_objects:
    obj.location[0] = 0 # x
    obj.location[1] = 0 # y