As asserted by knzhou in his answer, heat engines work in cycle and that's why it has to dump entropy before starting a new cycle (and that is the final nail in the coffin of perpetual motion of second kind).
Let $\delta Q_\textrm{H}$ be the amount of thermal energy that is taken up by the system from the hot reservoir. Therefore, entropy change of the system and reservoir respectively:
$$\mathrm dS_\mathrm{sys}= \frac{\delta Q_\textrm{H}}{T_\mathrm{sys_H}} \\ \mathrm dS_\mathrm{hot \,res}= \frac{-\delta Q_\textrm{H}}{T_\textrm{H}}$$
Now, since, it operates in a cycle, this must mean it has to dump that extra entropy $\mathrm dS_\mathrm{sys}$ as the net change in entropy after a cycle is zero viz. $$\Delta S_\textrm{cycle,sys}= 0\;.$$
In order to achieve this, the system dumps this extra gained entropy by giving off thermal energy to the cold surroundings or cold reservoir.
The entropy change of the system and entropy change of the cold reservoir respectively as: $$\mathrm dS_\mathrm{sys}= \frac{-\delta Q_\textrm{C}}{T_\mathrm{sys_C} }\\ \mathrm dS_\mathrm{cold \,res}= \frac{\delta Q_\textrm{C}}{T_\textrm{C}} \;.$$
Now, $\Delta S_\textrm{cyc,sys}= 0$ means
\begin{align}\mathrm dS_\textrm{universe}&\ge 0\\ \implies \mathrm dS_\textrm{sys} + \mathrm dS_\textrm{res} &\ge 0\\\implies \underbrace{\left(\frac{\delta Q_\textrm{H}}{T_\mathrm{sys_H}}+ \frac{-\delta Q_\textrm{C}}{T_\mathrm{sys_C} }\right)}_0 + \frac{-\delta Q_\mathrm{H}}{T_\textrm{H}}+\frac{\delta Q_\textrm{C}}{T_\textrm C}&\ge 0\\ \implies \frac{Q_\textrm C}{Q_\textrm{H}}& \ge \frac{T_\textrm C}{T_\textrm H}\tag{1}\end{align}
Now, $$W= Q_\textrm H- Q_\textrm C$$ and efficiency $$e\equiv \frac{\textrm{work}}{\textrm{heat absorbed}}= \frac{Q_\textrm H-Q_\textrm C}{Q_\textrm H}\tag 2$$
Using $(1)$ and $(2)$ we get $$e\le 1- \frac{T_\textrm C}{T_\textrm H}$$
So, how does the last result come?
It came because of the second law and that the change in entropy(a state variable) of the system/engine is zero over a thermodynamic cycle.