When we are determining the probability that only of two events A and B occurs, we do not want to include the case when both the events occur. The value of the probability of A occurring P(A), includes the probability of A and B occurring too. Similarly the probability of the event B occurring P(B), includes the probability of the events B and A occurring too.
We see that when we add P(A) and P(B) we are adding the probability that both A and B occur twice. It is therefore required to eliminate this part from the final result that we obtain. This is the reason behind subtracting 2*P(A and B) from P(A) + P(B).
As the probability that exactly one of two events A and B occur should not include the probability of both the events occurring, the required probability is P(A) + P(B) - 2*P(A and B)