There are (were) two east-west railway from Fife to Clackmannanshire, both originating in Dunfermline.
The Kincardine line is open from Alloa to Dunfermline, via Longannet but is used only by coal trains and the occassional enthusiast special. It is the line in question here.
The Dunfermline and Stirling Railway was the original mainline through west Fife, with its name suggesting the origin and destination. It is now the cycle way running from the outskirts of Dunfermline to roundabouts Clackmannan town. It closed in the mid 1980s when Comrie Colliery shut, the coal from which being the sole reason it was kept open. It was served by a separate station in Dunfermline; "Dunfermline Upper", what is now called Dunfermline Town was "Dunfermline Lower".
Map below summarises.
West Fife Railways by andy a, on Flickr
One difficulty is there is no south-facing junction at Dunfermline for trains to/from Edinburgh. They would have to run into Dunfermline then change direction, which would require a new bay platform or similar and pointwork to allow the change of running lines. Before the Stirling line opened to Longannet, coal trains from the Hunterston Terminal caused all sorts of congestion by having to run through the central belt, use the Forth Bridge, head into Fife as far as Thornton Yard where they could be turned, and then head back the other way through Fife and Dunfermline again to approach Longannet from the east.