You are describing my younger son too! But I can't get angry as I'm wried that way too, and use a kitchen timer often to stop myself from forgetting that I'm unstacking the dishwasher and wandering off to feed the cat then answer emails etc.
I've tried the following with my son:
At home, use a kitchen timer with a buzzer to get them to focus on simple tasks for a set time. Start off with very short missions - tidy your lego for 5 minutes or put all your dirty clothes in the wash basket in three minutes. He seems to be motivated by the timer. If she could take a silent buzzer into class and say, set herself the task of writing the opening paragraph in 3 minutes, then the developing paragraph in another 3 etc. that might help her stay on task, as it brings her back to what she should be doing with a physical buzz and stops the teacher having to remind her all the time.
The other possibility is that it's physically tough for her. Is she not very strong and sporty? Does she have dyspraxia? If so, holding the pencil gets so uncomfortable that they stop frequently and drift off. Use squeezy balls to strengthen their muscles. Squeeze in palm of hand and release as often as possible. Get her to play with it and grip it when she's watching tv. Maybe buy her some of those chunky ergonomically designed pens and pencils (WHS Smith had them when I looked) that are easier to grip.
Get her to write at home for longer stretches than she's used to - letters and shopping lists and To Do Lists.
Teach her the Biggles stretch to relax her arm if she gets writer's cramp. (Make your thumbs and forefingers into a pair of 'glasses' then put them in front of your eyes so that the inside of your palms are against your temples and your other fingers are touching your chin. Very big stretch.)
Play concentration games, like Pelmanism or 20 things on a tray covered by a cloth - take one off each time and she has to work out what it is.
Have you checked she's being correctly guided through the stages of what she needs to do? Does she understanding planning longer pieces of work and how that planning and note taking translates into the full sentences and paragraphs she's being asked for?
Suggest some tricks she can use at school to get her focused. One I've just made up for my boys to stop them starting every sentence with The is to start each new sentence with a letter of their name. So the first letter of each sentence in the first paragraph spells out her first name, and in the second para, her second name. It's a bit of a challenge but it gets them on task and makes the writing original.
Another I use with my students is to make sure they use all five senses when they describe a scene, but without mentioning the sense. (So not: It smelled musty. It looked dark. The door sounded creaky.
But The door creaked as I entered the dark and musty chamber
. etc.) Just having very specific things to focus on like this can help set the writing rolling.