TL;DR: computers are not autonomous entities like organisms, with any survival instinct. They just run instructions, and sometimes they run instructions we don't like, so we run other instructions to find the bad ones.
I started to say this in the comments, but I think there's a lot more to be said.
The virus metaphor is outdated and too widely used by people who don't understand how computers actually work. They try to liken them to living things, because they understand living things. Here's a better metaphor.
You are an office worker. You work for a giant mega-corporation, where you don't see your boss. You aren't ever told why you do your job, you don't even know what your company does. All you know is that you show up to work every day, and you follow your instructions.
There's a little window by your desk, which is the only way you ever interact with anyone else. You don't see anyone, but sometimes pieces of paper come through the window.
Your instructions are always the same at the start, but you have a huge pile papers at your desk. Some of these contain instructions, some of them contain things you've written. Sometimes your instructions will tell you to find a different piece of paper, and start using it as your instructions. Sometimes they tell you to change the pieces of paper, ripping them up, or erasing parts of them.
(This is what running a program is. Sometimes programs edit files, sometimes they run other programs, etc.)
Sometimes your instructions tell you to wait by the window for more paper to come. The paper might have a picture on it, it might have text, or it might have more instructions.
(This is what happens when a computer waits for mouse input or keyboard input, or something from a network (i.e. files)).
You do nothing but follow these instructions. You never know why, you never know for whom, but you just do it.
Sometimes, your instructions tell you to multitask. You have a pile of papers. You set a timer, and you work on the instructions from the top paper for 5 minutes. When the timer goes, you put that paper on the bottom of the pile, and do whatever is on the new top paper. (This is how computers run more than one program at once).
Now one day you're waiting for a piece of paper by the window, and you know when you get it, you're going to do whatever it says, because that's what the last piece of instructions told you to do. You get it, and it says to find some of your main pieces of paper, with your core instructions, and erase them. It tells you new instructions to put there. These are doing some strange things, like sending your files out the window to strange places, or collecting backup copies of all the things that come through the window. But what's important is, you don't think anything of it. They are just more instructions. You just do them.
This is what a virus is. It's just a set of instructions that you trick the computer into running.
Now, say you're a multitasking worker. You get one of these erasing instructions in the window. But, you're busy, so you put it onto the bottom of the pile. You look at the top of your pile of stuff to do, and there's a set of instructions marked "antivirus". It says to read through all your papers, and see if any of them look like their sample paper. You do, and you see that the erasing instructions is on your list.
Note that if you start running the virus instructions, you don't think anything of it. Without an antivirus, there is no attack, there is no immune response. It's not attacking you, it's just a set of instructions. The antivirus is just a TODO list that involves looking at your other instructions and finding ones that match a pattern. It's not trying to preserve the system as a whole, it's just a sheet of paper that someone gave you from the window, because it prevents other people from tricking you into doing stuff by putting stuff through the window.
Now, what about your "evolving" viruses? This is certainly possible, but let's look at what this entails. An evolving virus is basically a sheet of instructions that tells you how to make more instructions. It's a piece of paper that tells you to erase a bunch of your old instructions, and then put new ones in its place, but those new instructions also tell you to erase old instructions, and put new ones, and so on. So the original instructions aren't changing. The virus isn't mutating. Instead, it's just doing whatever it does, while also leaving behind instructions to create its next generation.
So, is it possible to do this? Yes. But it's extremely complicated. To have a program that changes itself, but having that sequence of changing not eventually converge to a program that does nothing useful, is incredibly complex.