you can do what the silver weapons do and use the same script (silverswordscript). but instead of filling the silver perk for the perk property, create a new perk with your magic effect as the perk's ability (entry point ability). that way the weapon will add/remove the perk when equipped/unequipped...... sort of.
there is a bug with hotkeys that breaks the script. if the player uses hotkeys to switch between weapons, the OnEquipped/unequipped lines in the script will not fire, and your perk sync will be thrown off (this is the case with all of the vanilla silver weapons as well)
another approach would be to use the same custom perk, and automatically give it to the player (via immediate quest or whatever), and condition it so that the ability will only activate when the sword is equipped. i'm not sure what condition is the weapon equivalent of WornHasKeyword, but i am sure one of those condition functions will allow you to weed out just your sword either via magic effect keyword or something similar.
if you want this ability to be used by NPCs as well, you can make the ability as a spell instead of a perk