I think the confusion arises due to difference in equations from Physics and Chemistry text books. The physics text writes $U=q-w$ while chemistry says $U=q+w$. From the physics text its mentioned that work done by the system is positive means $U=q-(+w)$ and work done on the system is negative means $U=q-(-w)$. THEREFORE, both are correct in their own way. Hope I've figured it out correctly.