The ideal gas law describes the relationship between pressure, volume, and temperature of an ideal gas at thermodynamic equilibrium. It also describes the PVT relationship for a gas experiencing a very slow deformation process (quasi-static, reversible), since a reversible process is just a continuous sequence of closely neighboring thermodynamic equilibrium states. But for a rapid deformation of a gas, the ideal gas law no longer allows you to calculate the gas pressure correctly (especially at the moving boundary where the gas is doing work), because it applies only at thermodynamic equilibrium, and a rapid irreversible process passes through a sequence of non-equilibrium states. We know from fluid dynamics that, what is happening in an irreversible rapid-deformation process is that "viscous stresses" contribute to the pressure at the moving boundary. So the pressure must differ from the ideal gas law.
Now for $P_{ext}$ vs P: $P_{ext}$ is supposed to represent the pressure of the surroundings at the moving boundary where work is being done, and P is supposed to represent the pressure of the gas at this interface. Whether a process is reversible or irreversible, by Newton's law of action-reaction, we must always have that $P=P_{ext}$. And, for thermodynamic equilibrium or for a reversible process, P can be determined from the ideal gas law (or other real-gas equation of state). But, for an irreversible process, we can't use the ideal gas law, so we are more limited. To calculate the work done at the moving boundary, we must impose the external pressure manually or by an automatic control system to dictate the pressure for calculating the work done by the gas on its surroundings.
So, in summary, for all processes, both reversible or irreversible, the work done on the surroundings is $$W=\int{P_{ext}dV}=\int{PdV}$$However, for an irreversible process, we can not calculate P from the ideal gas law, so we are stuck using $P_{ext}$, which must be specified by other means.
ADDENDUM
The force balance on the piston (assumed frictionless) reads $$P_gA-mg - P_{atm}A=m\frac{dv}{dt}$$where, if our "system" is the gas, $P_g=P_{ext}$ is the action-reaction pair at the interface between the system and surroundings. $P_{ext}$ is the pressure exerted by the surroundings (in this case, the inside face of the piston) on the gas. So we have$$P_gA=P_{ext}A=mg + P_{atm}A+m\frac{dv}{dt}$$
If we now multiply this equation by the piston velocity, we get $$P_gA\frac{dx}{dt}=P_{ext}A\frac{dx}{dt}=mg\frac{dx}{dt} + P_{atm}A\frac{dx}{dt}+mv\frac{dv}{dt}$$or, equivalently, $$P_g\frac{dV}{dt}=P_{ext}\frac{dV}{dt}=mg\frac{dx}{dt} + P_{atm}\frac{dV}{dt}+mv\frac{dv}{dt}$$If we next integrate this equation between time zero and time t during the process, we obtain: $$W_g(t)=W_{ext}(t)=mgx(t)+P_{atm}[V(t)-V(0)]+m\frac{v^2(t)}{2}$$Note that the work done by the gas on its surroundings is exactly equal to the integral of $P_{ext}dV$ and that the kinetic energy of the piston is included in this work. The piston is frictionless, so it can't damp the motion of the piston. Even so, do you think the piston will continue oscillating forever, or do you think there is some other physical effect present that will eventually damp the motion of the piston (after a long time)?
The effect I'm talking about is viscous stresses within the gas which allow the time variations in $P_g(t)$ (and, thus, $P_{ext}(t)$ to adjust in such a way that they act to slow the movement of the piston, and eventually bring it to a stop. So, in the end, V=$$W_g(\infty)=W_{ext}(\infty)=mgx(\infty)+P_{atm}[V(\infty)-V(0)]$$