He didn't deviate from the book...much
At least one Ring-Wraith does enter Bree in the night and is seen by Merry:
"I have seen them Frodo! I have seen them! Black riders!...Here. In
the village. I stayed indoors for an hour. Then as you did not come
back, I went out for a stroll. I had come back again and was standing
just outside the light of the lamp looking at the stars. Suddenly I
shivered and felt that something horrible was creeping near"
Merry continues his story:
"I went to pieces. I don't know what came over me." 'I do,' said
Strider. 'The Black Breath. The riders must have left their horses
outside, and passed through the South-gate in secret.'
Strider / Aragorn is aware that there are human enemies and ne'er do wells in the town who would gladly give the company up:
"They will know all the news now, for they have visited Bill Ferney;
and probably that Southerner was a spy as well. Something may happen
in the night, before we leave Bree".
Here is where the major deviation occurs:
'What will happen?' said Merry. 'Will they attack the inn?'
'No, I think not', said Strider. 'They are not all here yet' And in
any case, that is not their way They will drive these wretches to do some evil work; Ferny, and some of the strangers, and maybe, the gatekeeper too.
Here, we find some similarity again w/ between the film and the text:
[Aragorn] 'Stay here, and do not go to your rooms! They are sure to
have found out which those are. The hobbit-rooms have windows looking
north and close to the ground. We will all remain together and bar
this window and the door.
Nob, the hobbit working at the inn, sets up a decoy:
'Well Masters' said Nob, "I've ruffled up the clothes and put in a
bolster down the middle of each bed. And I made a nice imitation of
your head with a brown woollen mat'
During the night, the Riders (or someone - as Strider indicated earlier, perhaps Ferney or the like) entered and turned over the room:
"As soon as Strider had roused them all, he led the way to their
bedrooms. When they saw them they were glad they had taken his advice:
the windows had been forced open and were swinging, and the curtains
were flapping; the beds were tossed about, and the bolsters slashed
and flung upon the floor; the brown mat was torn to pieces."
In the text, the company departs Bree the following morning without interference from the Black Riders. So, in the book, the Riders do enter Bree and the company does hide from the Riders, and someone rousts the bedroom, but, in the text, the attack on the bedroom is not shown, nor is there any indication it is the Black Riders that perform the deed. Strider thinks any attack would be perpetrated by humans in Bree, not the Riders.
Although it's a very good scene from the film,
...what other reason would you need? ;)