How to copy object mesh with all modifiers applied

After much hair pulling and trying this and that and searching all over and taking bits of code from here and there, I managed to patch together something that does what I was hoping for.

#animation sequence duplication script by James Oliver, 2022_July_11

#Given a mesh with shape keys with keyframes and other animation keyframes,
#this script will output a series of shapes from frame frame-start to 
#frame frame_end with shape keys and animation data stripped. 
#The object must be selected.


import bpy

ctxt = bpy.context
selected_object_old = bpy.context.active_object

frame_start = 1
frame_end = 44


bpy.context.scene.frame_set(frame_start)
x = frame_start
while x <= frame_end:
    deep = bpy.context.evaluated_depsgraph_get()
    cleaned_copy = selected_object_old.copy()
    cleaned_copy.data = selected_object_old.data.copy()
    cleaned_copy.animation_data_clear()
    ctxt.collection.objects.link(cleaned_copy)
    evaluated_object = selected_object_old.evaluated_get(deep)
    clean_mesh = bpy.data.meshes.new_from_object(evaluated_object)
    cleaned_copy.data = clean_mesh
    x += 1
    bpy.context.scene.frame_set(x)