This problem is based on the concepts of Newton’s Third Law of Motion. The law states that “For every action, there is an equal and opposite reaction”. The most basic question that arises is that why don't action and reaction cancel each other out? This is because they act on two different bodies.
Suppose we take the cart as our system. Two forces act on this cart - the force applied by the horse in the forward direction and frictional force in the backward direction. The difference between these two forces accelerates the car forward.