When a body is moving, all forces produce work. It may be negative, positive or null.
Suppose we’re both pushing a huge box from the opposite sides: since you’re probably stronger than me, the box will move in my direction. However, I am still applying a force. My force and the displacement go in opposite directions, so my work is negative.
The same thing happens with friction: it goes against the movement, and it’s a force, so the work it does is negative.
What about putting a book in the top shelf? You’re pushing, and your force is parallel to the displacement (since you push upwards and the book goes up) but gravity is pushing down: it goes against the displacement. Once again, the work is negative.