From Fort William to Mallaig via Glenfinnan the steam train and the ordinary diesel train from Glasgow run over exactly the same tracks.
And it is almost impossible to do the steam train and return from Glasgow in the day, unless you travel from Glasgow to Fort William in one direction or the other in the seated car of the Caledonian Sleeper from/to Glasgow Queen Street Low Level.
To do this (on a weekday) you would need to leave Glasgow Queen Street (High Level) at 0822, arriving at Glenfinnan at 1249. The afternoon Mallaig bound steam train stops at Glenfinnan Station from 1331 to 1356 (so you will have time to look in the Station Museum before they arrive and invade the Museum).
As soon as the steam train leaves go and have lunch in the station Dining Car (an old Railway Restaurant Car).
(Do it the other way round, lunch first, museum after the steam train and you get free museum entrance).
You then have time to go and see the Jacobite Memorial at Glenfinnan before going to the viaduct for the eastbound steam train at 1519.
Your return train to Glasgow leaves at 1654, arriving at 2125.
At the same time the afternoon diesel train to Mallaig leaves from the opposite platform at Glenfinnan.
What you could also do is to return to Glasgow via Glencoe- the service bus #500 leaves from Glenfinnan at 1640 Monday to Friday, arriving at Fort William at 1710. The bus to Glasgow via Glencoe leaves at 1740, arriving at Glasgow at 2051 (so before the train).
The connection train to bus at Fort William is very tight, hence taking the bus from Glenfinnan. But you could equally take the train back to Fort William, have about 90 minutes in Fort William then take the 1910 bus back to Glasgow via Glencoe arriving at 2216.
Doing it that way you will see the Caledonian Sleeper train arrive in from the sidings at 1850.
You could of course just stay on the diesel train to Mallaig and spend the afternoon there (including seeing the first steam train on the platform there and then departing at 1410, and the second steam train arriving at 1506)