can you add a few lines in the very end that converts all absolute paths to relative?

Yes, you can add the following lines at the very end of the script to convert all absolute file paths to relative file paths:

for obj in bpy.data.objects:
    if obj.material_slots:
        for material_slot in obj.material_slots:
            if material_slot.material.node_tree:
                for node in material_slot.material.node_tree.nodes:
                    if node.type == "TEX_IMAGE" and node.image:
                        node.image.filepath = bpy.path.relpath(node.image.filepath)

for scene in bpy.data.scenes:
    if scene.library:
        scene.library.filepath = bpy.path.relpath(scene.library.filepath)

for cache_file in bpy.data.cache_files:
    cache_file.filepath = bpy.path.relpath(cache_file.filepath)

These lines use the bpy.path.relpath function to convert the absolute file paths of the textures, linked library scenes, and cache files to relative file paths.

linked_files_collect_addon_06.py