In Harry Potter and the Prisoner of Azkaban, why did the dementor attack Harry on the train? We know that they were looking for Sirius Black, but it cannot be an excuse for attacking Harry.
The scene plays out differently in the book and the film
The dementor doesn't attack him personally. It stands near him and Harry is simply affected more than his peers.
Standing in the doorway, illuminated by the shivering flames in Lupin’s hand, was a cloaked figure that towered to the ceiling. Its face was completely hidden beneath its hood. Harry’s eyes darted downwards, and what he saw made his stomach contract. There was a hand protruding from the cloak and it was glistening, greyish, slimy-looking and scabbed, like something dead that had decayed in water …
It was visible only for a split second. As though the creature beneath the cloak sensed Harry’s gaze, the hand was suddenly withdrawn into the folds of the black material.
And then the thing beneath the hood, whatever it was, drew a long, slow, rattling breath, as though it was trying to suck something more than air from its surroundings.
An intense cold swept over them all. Harry felt his own breath catch in his chest. The cold went deeper than his skin. It was inside his chest, it was inside his very heart …
Harry’s eyes rolled up into his head. He couldn’t see. He was drowning in cold. There was a rushing in his ears as though of water. He was being dragged downwards, the roaring growing louder …
And then, from far away, he heard screaming, terrible, terrified, pleading screams. He wanted to help whoever it was, he tried to move his arms, but couldn’t … a thick white fog was swirling around him, inside him –
‘Harry! Harry! Are you all right?’
In the original screenplay the scene plays out in very much the same way, although with some additional visuals to show that Harry is being especially affected.
A HAND -- slimy and scabbed -- a hand of death -- GRIPS the half-open compartment door, pushes it aside. REVEALS: a TOWERING, CLOAKED FIGURE, its face hidden beneath its black hood. CROOKSHANKS' hair rises and as she HISSES...
WHOOSHHHHH. The folds of the hood TREMBLE. A CHILL, RATTLING INTAKE OF AIR is heard. The FLAMES in Lupin's hands SPUTTER. A SOUND SWELLS in Harry's ears. Eerie. Painful. The sound of a WOMAN SCREAMING. Harry's eyes roll up, eyelids fluttering.
And then... a SILVERY WHITE LIGHT drifts from his mouth. The world spins off its axis and Harry falls... glasses tumbling hard to the ground... then Harry... the muscles of his jaw twitching. THUNDER CRACKS. LIGHTNING paints the ICY windows...
With a DESPERATE GASP, Harry opens his eyes. Blinks. DUSK IS GONE. The windows BLACK.
Somewhere between the writing of this version of the script and the filming, the decision was taken to include the Dementor coming into the carriage and to include some footage of Lupin using the Patronus. Presumably this was done to establish both the Dementors and the Patronus charm to the audience.
Personally I think it was NOT a coincidence. The Dementor could have attacked any other cart. But remember, Harry has a piece of Voldemort's soul from when Voldemort tried to kill Harry in him as well. The Dementor could have have seen the presence of a dark wizard and thought it was Sirius Black.