So what you are looking for are the technical specifications of your robot, you can download them for free from https://xpert.kuka.com/service-express/portal/
On my version the relevant section is 6.4, page 63 which provides you with the complete pin out.
In your sketch, 0V should be pin 10 and 24V should be pin 9. The two digital outputs are pins 1 and 2.
Just from that data, your sketch sounds plausible. However, you always need to map inputs and outputs in WorkVisual, so that the robot knows that pin 2 on X41 is equivalent to your $OUT. That is not a default, so if the robot configuration has been changed since the last time someone used it, the digital IOs may not be configured at all.
For troubleshooting I would recommend using the Display / Digital IO menu rather than KRL code. Just note that to change the state of an output you need to hold down the button on the back of the smartPad, as if you were moving the robot in T1.
You mentioned a "previous student", so any re-configuration of the robot via WorkVisual should probably be done by the lab staff.
Hope that helps!