Python - How to detect when user opens another file inside Blender? Edit: I think I have found what I was looking for bpy.app.handlers.load_post, but will leave it open for maybe better suggestions.
I have a class variable that is stored in bpy.types.Scene.my_class, which I access with context.scene.my_class.
The problem I am having is that I need this class to be deleted and recreated when the user opens another .blend file from within Blender. The only way I can think of is to store path + file_name to the current .blend and check it before running the rest of my script to decide if my_class needs to be refreshed.
Using a handler to remove my_class:
from bpy.app.handlers import persistent
@persistent
def handler_new_scene(scene):
    del bpy.types.Scene.my_class

I think del scene.my_class will work also, or scene.my_class = None if still need to have the attribute.
In the register function I add my function to the load_pre handler, which will run before a new scene is loaded:
bpy.app.handlers.load_pre.append(handler_new_scene)