The more scenic rail journeys tend to be in north Wales. Of the direct lines from Cardiff, that going up the Marches is the most scenic. This is the line following the border between Wales & England and has at least one train per hour. Shrewsbury & Ludlow are both historic places where trains on this route stop. Hereford also could be worth a stop as it has an ancient Cathedral - but is more of a walk from the rail station. http://www.ludlow.org.uk
If you are a real rail fan and want to see the scenic Heart of Wales, you could take the Heart of Wales Line = a slow single track line linking Swansea with Shrewsbury (with Craven Arms being the place to change if you don't want to go to Shrewsbury). You could do the route in either direction but check the timings carefully.
I would not make any stops when on the Heart of Wales line as the next train won't be for 4 hours! You can test the schedules here - I would put in for Cardiff to Llandrindod Wells to see how the timings work out. www.nationalrail.co.uk
http://www.arrivatrainswales.co.uk/ExploreWales/HeartofWalesRanger/ (Click MAP for route).
(If going westbound, you may have to leave Cardiff at 8am). http://www.heart-of-wales.co.uk/timetables.htm
As an alternative to the above, you could travel by rail or bus to Merthyr (via the old coal mining valleys of south Wales). From Pant - on the north side of Merthyr, the Brecon Mountain Railway operates into the Brecon Beacons National Park.
If you are interested in this option, use this website to find how to reach the BMR. http://www.traveline.cymru
If you just want a short rail journey - though not exactly scenic, you could take a train from Cardiff to Llantwit Major. Visit St. Illtyd's Church (SW of station) , then walk for almost 2 miles down to the beach - use the path through the meadows when you reach the stream. The cliff top path going west from the beach is also nice.
I note that you are already likely to be using the Marches Line on your way to north Wales. If you wish to go on a longer train journey but not on the Marches route, I would suggest going west to Tenby. It is not particularly scenic - just ordinary countryside for the most part. On present weekday schedules, a suitable train leaves Cardiff at 9.04 to arrive Tenby at 11.41. Depart Tenby at 15.41 to arrive back in Cardiff at 18.22. Westbound & eastbound will involve 1 change of train. See www.nationalrail.co.uk & click 'details'.
Tenby is a stunning seaside town .http://www.tenbyvisitorguide.co.uk