How do I prevent curd from getting sour?
As you already said yourself, cooling it will be easiest. Either use a cooled lunchbox with an ice pack insert, or, if taking it out of the refrigerator at morning, carry it in a thermos flask. 

Alternatively, you have to get it out underfermented and let it ferment properly during these 4-5 hours. If you are taking just-ready room temperature curd, you can instead start the curd later, or start with cooler milk, or use less starter. If you are taking it from the fridge, you can start putting the curd into the fridge before it's done, so it reactivates and finishes fermentation in your bag. In any case, you will need lots of experimentation until you have the process such that the curd is properly done by the time you eat. Also, a few degrees Celsius difference in your environment will make it necessary to tweak the parameters. 

Theoretically, the third option to try would be to kill off the culture when the curd is done, by heating it. But too little heat and the culture will survive, while too much heat and you will end up with quark. So this is only used in industrial settings.