How do colds and flu not infinitely recur?
Short answer:
Because your immune system adapts to the virus causing the flu or the common cold and, thus, you become immune to it.

Longer answer:
When B cells first encounter an antigen (usually a protein on the surface of a pathogen), the antigen attaches to a receptor, stimulating the B cells. Some B cells change into memory cells, which remember that specific antigen, and others change into plasma cells. Plasma cells produce antibodies that are specific to the antigen that stimulated their production.
After the first encounter with an antigen, production of enough of the specific antibody takes several days. Thus, the primary immune response is slow and that's the reason you experience the symptoms of the disease.
But thereafter, whenever B cells encounter the antigen again, memory B cells very rapidly recognize the antigen, multiply, change into plasma cells, and produce antibodies. This response is quick and very effective.
This means that, theoretically, you shouldn't be able to become sick twice by the same virus.
However,
virus are very prone to mutations. If these mutations occur in the genes that code for antibody-binding sites, the antibodies produced by B Cells become less effective. This is called Antigenic drift and the reason you might catch the Flu every year (because, with enough time, the virus antigens become different enough to &quot;fool&quot; your immune system).

Also, there are a few explanations why the flu has a seasonal pattern, with a peak usually at winter. One of the theories postulates that in cold weather, people tend to stay indoor, favoring virus transmission.
Recently, an interesting article was published that found that:

transmission of influenza B viruses is enhanced at colder
temperatures, providing an explanation for the seasonality of
influenza epidemics in temperate climates

source