Suppose a body (say $5\text{ }kg$) is kept at rest on a horizontal table of some friction coefficient (say $0.2$). If a force of $20\text{ }N$ is applied to the body for just a moment (i.e. infinitesimal interval of time), it moves in the direction of the force. We know that it moved because it gained energy from the force. And when the whole energy (which was gained earlier) is released, it comes to rest. It means that the body didn't use its own energy and the external force also did some work. So the energy of the body is conserved.
But from the law of C.O.M.E energy is not conserved when an external force does some work.
I am confused kindly clarify my doubt.