Why do atoms have electron Affinity?
Actually, not all atoms are stable, at least not in the gas phase, which is where we measure the electron affinity. You should first read Why do atoms &quot;want&quot; to have a full outer shell? for detailed elaboration.

Now, electron affinity involves the gain of an electron to an isolated gaseous atom, but not all atoms actually want to gain an electron, i.e., they are already pretty stable. This is precisely the reason why elements like the noble gases or nitrogen have negative electron affinity i.e. you need to supply energy for them to accept an electron.

Also read: Are there any major exceptions when comparing electron affinity?



So, in short: "Atoms are stable so..." not always, in fact, such atoms are in the minority. "...how can they pull electrons..." read the first link. "how do they have any electron affinity at all?" we can always supply excess energy to make an atom accept an electron, forcibly. So, the only difference for stable vs non-stable atoms would be the sign of electron affinity.