Oh, didn't notice the other guy's post, but it's relevant here because it confirms UPS issues with on_entity_died and that this bug is a product of how the solution is designed.
Because this script is called on EVERY entity death it's going to generate a lot of script load (see the other user's comment about asteroids) and it'll break when a mod does something in a way your script isn't designed to handle.
In my case, it's basically because of a simple code oversight (the variable isn't initialised in on_entity_died because the script is called by the game before it bootstraps mod vars and the function doesn't itself initialise surfaces), in the other case it's probably because the biter-factions-ng mod has custom scripts for its deaths and don't include data your scripts expect in its death events.
In all cases, calling on every entity death is gonna result in a LOT of script load, especially as the game progresses and you will probably keep running into bugs relating to on_entity_died.
I'd definitely recommend looking into:
https://lua-api.factorio.com/latest/classes/LuaBootstrap.html#on_init
https://lua-api.factorio.com/latest/concepts/EntityPrototypeFilter.html
https://lua-api.factorio.com/latest/classes/LuaPrototypes.html#entity
Using the game's own filtering to establish your whitelist during the initialisation phase is gonna be MUCH better for UPS. Of course mod compatibility is still kind of a problem, but it's better to use the game's internal tools and then if a mod breaks your mod, it's not your fault and not your problem to patch. ;)