Getting inside a cell and changing DNA is what a virus is good at. Our immune system doesn't produce viral structures.
Attaching antibodies (those 3-D shapes) to pathogens and using pyrogens and killer cells - THAT the immune system does.
Introducing DNA changes to the pathogens that prey upon you is an ineffective method, because you cannot ‘get’ them all at once, and the more detrimental the disadvantage, the more those unaffected will dominate subsequent generations.
So even if the immune system...
a) created viral like particles that could enter the bacterial cell and introduce new DNA.
b) the new DNA was to the disadvantage of the bacteria.
Then.....
c) the bacteria with the disadvantage would be out-competed by those without it.