Penicuik's original station on the Peebles Railway was a mile or so from its centre and not easy to access thanks to the hilly terrain. An approach by the townsfolk for a separate branch into the town was rejected, resulting in the local paper mills' proprietors - and other gentlemen from the district - establishing the Penicuik Railway Company to make progress with one independently, enabled by a Parliamentary Act of June 1870.
Although only 4¼ miles in length, the branch - engineered by Thomas Bouch and built by John Waddell - presented considerable challenges, costing about £12,000 per mile and crossing the River North Esk seven times. Two short tunnels were driven through spurs of land whilst a third, of 248 yards, was effectively created by covering the line as it passed close to the Roslin Gunpowder Mills. This iron structure was later dismantled, the mills having closed in 1954.
The branch opened to goods on 9th May 1872, slightly later than contractually stipulated, resulting in the contractor suffering a penalty of £10 per day. Passenger services were inaugurated on 2nd September.
The shorter of the two tunnels, at 74 yards in length, drove the railway under the B7026 - known locally as The Brae - just east of Auchendinny Station. The east portal is stone-built, featuring long triangular wing walls to both sides. The tunnel itself is horseshoe-shaped in profile with a five brick thick lining, initially curving to the north before straightening. Its refuges have been blocked up as part of the conversion work undertaken to host the popular Penicuik to Dalkeith Walkway. High on the north sidewall are substantial insulated brackets, used to carry telegraph wires. The west portal has only one wing wall; the south side abuts a road bridge over the River North Esk. Immediately beyond the portal is a single-span bowstring girder structure that carried the railway over the water.
Closed to regular passenger traffic in September 1951, the branch continued to carry freight until it succumbed to Beeching's reshaping on 27th March 1967, driven by the repairs necessitated by two landslips.