Pearls are formed by oysters as a defense mechanism against irritants, such as foreign particles or damaged tissue. When an irritant enters an oyster’s shell, the oyster secretes layers of nacre, a glossy material made of calcium carbonate, around the irritant. Over time, these layers build up to form a pearl. The process is influenced by factors like water quality, temperature, and the type of irritant.