The work done by an external force on a particle changes its kinetic energy. However, internal forces must also be considered for a system of interacting particles. The potential energy formulation helps formulate the effect of internal forces. The net work done by an external force can be written in terms of the total change of mechanical energy, which includes both kinetic and potential energies.
In the presence of a non-conservative opposing force, like friction, some part of the work done by an external force is lost as thermal energy. As layers of the object on which the force acts and layers of the opposing ground collide, the molecules along the colliding layers interact via electromagnetic forces, and the layers heat up. Eventually, some part of the work done by the external force goes on to heat the layers and is lost as irreversible thermal energy. The total work is obtained if this lost thermal energy is added to the change in kinetic and potential energies.