Why use Optcoupler + Mosfet?
It adds another layer of protection even with 24V. If you screw up, screwdriver or test probe slips and shorts two connections together (or the wrong ground connection opens up) you're much less less likely to ruin your micro board. Your choice, there's not a human safety reason if the 24V has proper galvanic isolation as well as a common ground. 

Since the 4N35 is so very painfully slow, using it degrades the switching of the MOSFET. This could be dealt with by using a somewhat better part and/or squaring up the signal on the other side of the barrier, but I think this is a major downside. 

Real product designs would probably not use the opto unless there was some reason to keep a noisy 24V supply completely separate. In development, it's not uncommon to temporarily add isolation from mains or high power supplies. Or maybe just add some 10K resistors and a buffer. 

It tends to ruin your day if excessive voltage finds its way into the wrong place and destroys the test object and your computer motherboard at the same time!