Externalities are defined as costs (or benefits) of economic transactions that are borne (or enjoyed) by people who are not part of the transaction. Externalities are a market failure because they cause the prices of the goods to not reflect their true costs.
The reason that we assume there are no externalities in perfect competition is because it is sort of a model. So assuming no externalities is like assuming no friction in physics.
Perfect competition is supposed to cause there to be allocative efficiency -- it is the perfect market structure. So in order to have it be that way, you have to assume there are no externalities.