The trap is the sign. W = P ΔV is the work done by the gas, so when the gas is compressed ΔV is negative and W is negative: the work is done on the gas, by the surroundings.
For a gas in a cylinder with a movable piston, the work done by the system against a constant pressure P is ΔW = P ΔV, where ΔV is the change in volume of the gas (NCERT Class 11 Physics, Chapter 11, page 231). Use the change in volume, not the final volume.
At constant temperature the pressure changes as the volume changes, so NCERT adds up ΔW = P ΔV over the whole process. For an ideal gas going from V₁ to V₂ this gives W = μRT ln(V₂/V₁) (NCERT Class 11 Physics, Chapter 11, page 234). For V₂ > V₁ the work W is positive, and for V₂ < V₁ it is negative. In an isothermal compression, work is done on the gas by the environment and heat is released (NCERT Class 11 Physics, Chapter 11, page 235).
Why does the heat leave? For an ideal gas the internal energy depends only on temperature, so it does not change in an isothermal process. The heat exchanged equals the work: Q = W (NCERT Class 11 Physics, Chapter 11, page 235). In the Carnot cycle, the heat released by the gas in its isothermal compression is also the work done on the gas by the environment (NCERT Class 11 Physics, Chapter 11, page 238).
At constant pressure the work done by the gas is W = P (V₂ − V₁) = μR (T₂ − T₁) (NCERT Class 11 Physics, Chapter 11, page 235).
Watch-out: write the sign of W as work done by the gas. The phrase "work done on the gas" flips it. Use ΔV = V₂ − V₁, with V₂ the final volume.