Hi there -- while we've approved this question, we'd like to remind any potential respondents to keep their answers related to conscripts in the World Wars, as our "20-Year Rule" prohibits discussion of events after 1997. Thanks!
At that moment a strong rabble of tired, hungry and thirsty stragglers approach me from the east. I go out to meet them.
'Where are you going?' I ask.
One says one thing, one another. They are marched to a water reserve, given a drink and hunted back to the fight. Another more formidable party cuts across to the south. They mean business. They are damned if they are going to stay, it's all up. A young sprinting subaltern heads them off. They push by him. He draws his revolver and threatens them. They take no notice. He fires. Down drops a British soldier at his feet. The effect is instantaneous. They turn back to the assistance of their comrades in distress.
Lieutenant Colonel (later Brigadier General) F.P. Crozier, a battalion commander of the 9th Royal Irish Rifles (107th Brigade) describing attempts to halt the unauthorised retreat of several groups of demoralised and exhausted soldiers on 1 July 1916 (first day of the Battle of the Somme).
An Officer's Ultimate Sanction, quoted in The Western Front Companion Mark Adkin (Ed.), p214
The prevention of desertion was a constant struggle for the British army in WW1; authorities were essentially fighting against men's natural reaction to remove oneself from intense danger, especially amongst the New Army volunteers who had no idea of what they were getting themselves into, and the less motivated post-1916 conscripts. The reaction is entirely understandable; on the first day of the Somme (the day Crozier is writing about), some of the volunteer ('Pals' and 'Service') battalions who were going into action for the very first time faced inconceivable volumes of enemy fire (for example, the 10th West Yorkshires were caught by enfilading machine guns at the Fricourt/Tambour Crater area and destroyed almost completely, with just one officer and twenty men making it back to British lines from the entire attacking battalion). Artillery bombardments could last for hours or even days; men in a position under sustained 'drum fire' (a technique where the guns fire so that a shell bursts every few seconds, rather than in one big salvo followed by a pause) could be left utterly dazed and insensible, their morale entirely spent. Even the most experienced and hardy soldier could only take so much:
In the trenches a man’s willpower was his capital and he was always spending, so that wise and thrifty company officers watched the expenditure of every penny lest their men went bankrupt. When their capital was done, they were finished.
Lord Moran, 1/Royal Fusiliers, The Anatomy of Courage, London, Constable, 1941
So desertion in the face of the enemy was absolutely a problem in WW1, although it's difficult to get an clear sense of how big the problem was from available sources. We can look at statistics for the number of men sentenced to execution and imprisonment for desertion, but this doesn't give an accurate picture of the issue: men in supply and logistics absented themselves from rear areas, never having seen the enemy, for example, and the man Crozier saw executed on the battlefield was unknown and would have appeared in no official statistics. A number of pretty severe riots and mutinies occurred, such as the one at Étaples.
Much desertion in action was headed off by strong policing of the 'Battle Zone', the forward fighting area (that included the fire trenches back to the reserve lines and support positions) with a rear boundary some way back that was held by either Brigade/Divisional units assigned to the task or by dedicated Military Police units. They were watching out specifically for men attempting to leave the forward lines without permission, and so acted as a 'back-stop', and would ideally herd the men back into action (much as Crozier attempted), arresting them only if necessary.
I don't think you can accurately compare it with the Iraq example you mention, though, for two other major reasons.
The first is the overwhelming notion of 'duty' (to 'King & Country', to home and family, to fellow soldiers and the cause of defeating the enemy aggressor, to ideals of 'manliness' and 'honour') that existed at the time. It's hard for us, a century later, to get a real appreciation of just how strongly these themes were reinforced by upbringing, through religion and in education. They were a powerful means of ensuring that men first joined the forces and then followed their orders to the point of self-sacrifice rather than face shame:
‘At a time like this I couldn’t be anywhere else but here. We have all been brought up at home, in school and church to a creed which places our duty to our country next to our religion, and I should not have been a true son if I had stayed at home instead of coming out here.’
Second Lieutenant Frank Potter, 14th (Service) Battalion York & Lancaster Regiment (2nd Barnsley Pals), letter to parents, 27 June 1916.
published in We Will Not Fight: The Untold Story of World War One’s Conscientious Objectors by Will Ellsworth-Jones, Aurum Press, 2008
The second was brutal military discipline. You can see on this page just how many crimes were punishable by execution or penal servitude. Conscripts (and volunteers) were incorporated within a military structure with long established traditions, governed by a well-developed set of rules (the 'King's Regulations'), along with penalties for transgression. I wrote a bit more about the issue of desertion in this AskHistorians question.
I can't comment much on the Second World War experience, but for this I would strongly recommend a superb book called The Deserters: A Hidden History of World War II by Charles Glass.