Following the Allied invasion of Italy in September 1943, as the Allied Forces progressed northwards, they needed to use the civilian railway system which had been extensively damaged both by Allied bombing and by the retreating Germans. This involved not only replacing the track but also the signalling infrastructure and in some cases the electrical supply for those sections which operated electric trains.
A unit called the Lines of Communications Railway Signals was formed to do this work. Initially it consisted of five US Army railway signal sections and two British Army railway telegraph companies.There were was also a contingent of employees of the Italian State Railway (Italy having surrendered on 3 September 1943). The overall commander of this unit was the US Director General Military Railways Service. However when the US railway units in Italy were withdrawn in June 1944 to prepare for Operation Anvil (the US landings on the South coast of France) the LofC Railway Signals unit came under the command of the British Director of Transportation.
To quote from R F Nalder
The Royal Corps of Signals - a History of its Antecedents and Development 1958:
These units repaired the circuits for train control, which ran alongside the tracks, and also manned the railway signal offices. The Chief Signal Officer L of C was kept informed of the long line requirements of the railways and included them in the plans for the theatre system, from which they were provided.
One of the major problems they faced was interference of the signals caused by the adjacent high voltage power supplies, mainly due to faulty equipment in the generating stations and poor bonding of the running rails.
The Italian campaign did not end until April 1945 when the remaining German forces there surrendered.
I imagine that something similar must have been needed in North West Europe following D Day, but Nalder's book gives no specific details about the railways. Based on what happened with repairing the fixed telecommunications infrastructure generally during the push East towards Germany, it appears that extensive use was made of the existing civilian Post Office and Telegraph companies to restore their own circuits, so perhaps the same occurred with the railways, with only minimal input from the Royal Signals.
Unfortunately I found no specific reference to 5 Headquarters Company either, so I can't say for sure which theatre it was operating in, although given the dates you provide, I would favour Italy.