Her dark material ... Munro, who is tackling the festival's Enlightenment theme with a play about witch-burning. Photograph: Murdo Macleod

The following correction was printed in the Guardian's Corrections and clarifications column, Thursday 1 October 2009

The article below said that "witch burnings in England had ceased in the previous [17th] century". In fact, England – unlike Scotland – did not go in for burning people accused of witchcraft (though it did burn people for heresy, among other crimes).

Rona Munro wrote the final story of the "old" Doctor Who, or the "classic" Doctor Who, as she calls it – as opposed to its wildly popular, cultish reinvention by Russell T Davies. And now the Aberdonian playwright and screenwriter would like something to be known. "This," she says with mock portentousness, as she munches a sandwich at the Traverse theatre's rehearsal room in Leith, Edinburgh, "is my chance to say it. I don't think the Doctor should have fallen in love with anybody. I think that's wrong. I don't think there should be any snogging or any sexual tension because" – she gets even more mock-grand – "he's a time lord, and his companion is but a mortal." Despite the good cheer, you know she means it. The running sexual tension between the Doctor and his various sidekicks has, she reckons, been "lazy".

Lazy is the last word anyone would use to describe the latest venture by Munro. Her new play The Last Witch – directed by the Traverse's Dominic Hill and part of this year's Edinburgh international festival – is based on real events: in 1727, a woman, who may or may not have been called Janet Horne, was burnt as a witch. She was the last woman in Britain to meet such a fate (witch-burnings in England had ceased in the previous century). Two years later, Francis Hutcheson would take up the chair of philosophy at the University of Glasgow, and effectively propel the Scottish Enlightenment into full swing.

The apparent contradiction of these events – raging superstition set against the onward march of scientific and rational thought – has been investigated with a historian's zeal by Munro, who studied the subject at university. The result is a fascinating dramatic treatment of what Edinburgh international festival director Jonathan Mills has called "endarkenment" – an unsettling counterpoint to the Scottish Enlightenment, which this year provides the over-arching idea for the festival programme.

Very little is known about Janet Horne (hers was a name witches were often given in Scottish folklore). She was burnt in Dornoch, in the Highlands north of Inverness (perhaps more famous now as the setting for Madonna's marriage to Guy Ritchie). She had a daughter, Helen, who was supposedly born with a deformed hand. On being led to the fire that would kill her, she is said to have remarked on its "bonny warming". And then, according to Munro, there are ways in which her death mysteriously bypassed the normal legal procedures for a witch-burning. There is just enough tantalising information, then, from which to weave a good tale; and plenty of intriguingly unsolved questions for the playwright to answer.

Munro has taken her cue about Janet's character from that "bonny warming" comment. "It seemed to me that either she was a poor old soul who had Alzheimer's, and her neighbours had turned on her – or else it's an extremely defiant thing to say," says Munro. "The latter was more appealing in terms of creating the character." According to her (extensive) reading on Scottish witchcraft, "You've got women going to the stake protesting their innocence; you've got others who say they are witches because they are tortured; and a third group who say, 'Yes, I am a witch.' I thought that was quite interesting. I think I was also looking at what happens when you are a big personality in a small place. If she'd been in another time, Janet would have started the local am-dram society, or she would have been the person on the local council who ran everything."

Janet, then, truly believes she has supernatural powers: "She is always thinking, 'I just have to concentrate a bit more and I will get it right,'" says Munro. She is also a fish out of water in Dornoch – she had been a lady's maid in Italy, according to the scraps of information passed down about her, and Munro speculates that perhaps she had served an exiled Jacobite family and later returned to her remote Highland birthplace, a town of grinding poverty. There is precise information – albeit from later in the century – about Dornoch, contained in the 1790s Statistical Account of Scotland, a detailed record based on information supplied by parish ministers. "In Dornoch in 1799, there were no potatoes, no turnips, no onions," says Munro. "There were peas, rye and barley. The people aren't really fishing, because farming folk don't really go out and fish. So their diet is shellfish, and peas and barley and rye . . . and that's it. So, you would sell your soul for a pie, wouldn't you?"

What also fascinates Munro is the pervasiveness of belief in witchcraft in Scotland, despite all the forces that were moving the nation towards the confident intellectual landscape represented by the likes of David Hume and Adam Smith. "In Arthur Miller's The Crucible, we are talking about big mobs and mass hysteria. But in Scotland, it's a very cold legal thing. It goes through the courts; there are ways you can accuse the witch and ways you can't. An accusation has to go to the kirk session and then to the higher sheriff court, and then it has to go to a higher court again. It's very calculated. I realised that what you are dealing with is a belief in witchcraft at all levels of society. Scotland was an educated nation. You are talking about well-educated people who believe in witchcraft and have a legal process for dealing with it. And then you've the question of why one woman was called, in Dornoch, a good 60 years after the last witch was killed anywhere."

Munro, 49, was brought up in Aberdeen and its environs, the daughter of a geologist at the university and a radiotherapist. She was just eight when she realised she wanted to be a writer. "When I was at primary school, some of the girls did a play about Gypsies – in fact I have no idea what it was; it could have been The Pirates of Penzance for all I know. I thought this was the best thing I had ever seen, so then I wrote a play about Gypsies. A lovely teacher helped me stage it – and I was off." After Edinburgh University, she took cleaning jobs while she wrote, and had some lucky early breaks - commissions for plays, screenplays and radio plays.She moved to London after her partner at the time, and father of her now 18-year-old son, moved south for work. "I tried staying in Scotland on my own, but that was not working, and I thought we might split up, so I came down to London and we split up anyway. At that point, it was about making sure Danny had a relationship with his dad."

She thinks of herself as "a woman writer, a feminist writer and a Scottish writer – and I hope all those things inform the writing rather than define it". The feminism in her work is quiet but pervasive, not only in The Last Witch, but in plays such as 2002's Iron, which memorably, and with a bitter twist in the tail, charts the relationship between a woman imprisoned for murdering her husband, and her daughter. Munro's life as a single parent has, she says, certainly taught her discipline. "At least, as a writer, you can get a child off to sleep and get to work. And it was really good for me, knowing I'd get a chunk of time and no more." For Munro, there was never time to get hung up, because she had to get paid. "Being less precious about it is an enormous gift."

The Last Witch will inevitably be compared to The Crucible. Does it, like Miller's play, contain an urgent modern message? "I think the resonance is this: if you have a festival that's about Enlightenment, you are focusing on a time when society became secular, when science won out over religion, when, by the forces controlling society, we meant economic forces rather than God or the devil.

"If you look at the Enlightenment, it's all clean lines, and sharp stone columns, and people gazing into a bright clear future where everything is going to be quantified and man will be master of his own fate. But look at the period before the Enlightenment and people tend to say, 'At the end of the day, there is nothing you can do because some things are beyond our control.' And I feel that's the period we are going back to. The certainties of the Enlightenment are no longer our certainties."

It's a bleak message from what promises to be a dark, gripping unsettling drama.

The Last Witch is at the Royal Lyceum, Edinburgh, 23-29 August. Box office: 0131-473 2000.