Yes, I don't see why not. You will be travelling on a permitted route and your ticket is available for break of journey.
(edit: Just a thought I think that you will have to continue your journey, if on the outward portion, round the Fife Circle via Cowdenbeath to Kirkcaldy to pick up your connecting train to Perth/Pitlochry, otherwise you will have a double back between Inverkeithing and Dunfermline - & I'm sure there is no easement for that)