Before Julia died she had told her sister Helen about hearing a strange whistling but could not tell exactly where it was coming from. Helen explains to Holmes and Watson why she is presently occupying the room where Helen died and sleeping in Helen's bed.
Two days ago some repairs were started in the west wing of the building, and my bedroom wall has been pierced, so that I have had to move into the chamber in which my sister died, and to sleep in the very bed in which she slept. Imagine, then, my thrill of terror when last night, as I lay awake, thinking over her terrible fate, I suddenly heard in the silence of the night the low whistle which had been the herald of her own death.
When Holmes inspects the three adjoining bedrooms at Stoke Moran, he remarks that the extensive repairs to Helen's bedroom seem totally unnecessary, which suggests that Dr. Roylott was only having them done in order to force Helen to move into the only other available bedroom, which is Helen's former bedroom and is situated right next to Roylott's. Helen is already understandably frightened at having to sleep in the room where Julia died and to sleep in her sister's bed. But then when she hears the "low whistle" Julia told her about she becomes terrified. This whistling is what prompts her to travel to London early the next morning and consult Sherlock Holmes.
Evidently what Dr. Roylott is doing is sending the snake through the ventilator late at night when he can be sure Helen is asleep. But he has to call the snake back through the ventilator before daylight. Otherwise Helen might wake up early and be able to see the snake. So Roylott has trained the snake to return when it hears the furtive whistle. It is given a saucer of milk as an inducement to return. (This sounds very much like Pavlovian conditioning.)
Doyle does not say much about what the snake does after it slips through the ventilator and slides down the dummy bell-rope onto the bed beside the sleeping girl. The snake would not be motivated to bite the girl without provocation. There is a strong implication that this swamp adder, coming as it does from a hot climate, would be seeking warmth and might actually crawl under the covers and curl up beside the girl's warm body. It is mentioned many times that the weather is very cold. Helen mentions that it was also a cold night when her sister died.
It was a wild night. The wind was howling outside, and the rain was beating and splashing against the windows.
Therefore the snake would probably not try to escape from captivity, although it might at least be possible for it to crawl under the bedroom door. The most likely way in which the girl would be bitten would be if she turned over in her sleep and ended up lying right on top of the loathsome speckled reptile. Then it would surely bite her through her nightgown. That was probably what happened to Julia two years earlier. Julia may have been sleeping with a poisonous snake beside her for a number of nights before the snake finally struck.