make sure whether the corresponding .desktop file exists while creating the pinned items icon;
check the same for each item while saving pinned cache file.
In result, invalid items won't appear in the list (except for the resident instance, but you can unpin them there), and will be deleted from the cache file on the nearest change.
https://www.reddit.com/r/swaywm/comments/ynbcc1/comment/ivwx58z/?utm_source=share&utm_medium=web2x&context=3