Well, maybe "makeUnionsUnknown(K, Set)" and then:
rule write-specific() => makeUnionsUnknown(.K, Mods) ~> writeBytes()

And then makeUnionsUnknown can pull out a new SetItem when the first argument is .K.