Memory-based acquired immunity evolved in higher vertebrates based on the ability to differentiate foreign organisms (e.g., pathogens) from selfcells. While we still do not understand the basis of this, two corollaries of this ability have to be understood.
One, higher vertebrates can distinguish foreign molecules as well as foreign organisms. Most of the experimental immunology deals with this aspect. Two, sometimes, due to genetic and other unknown reasons, the body attacks self-cells.
This results in damage to the body and is called auto-immune disease. Rheumatoid arthritis which affects many people in our society is an auto-immune disease.