Dozens of MSPs weren't identified as Scottish taxpayers
HMRC's deputy chief executive said 45 of Holyrood's 129 members had been issued with incorrect code.
HMRC bosses failed to identify almost a third of MSPs as being Scottish taxpayers.
Jim Harra, the deputy chief executive of HMRC, said 45 of Holyrood's 129 members had been issued with an incorrect code for 2019-20.
He said he was "not pleased to learn that the mistake had been made".
He addressed the issue as he faced MSPs on Holyrood's Public Audit Committee, and convener Jenny Marra told him she was one of those affected.
Mr Harra said: "We identified 45 MSPs where we had sent them an incorrect 19-20 code which did not identify them as a Scottish taxpayer.
"That was because of a clerical error in the tax office that looks after the affairs of Scottish parliamentarians."
Pressing him on the issue, Ms Marra said: "We're not asking these questions because we're concerned about our own tax affairs, we're concerned about it because it is a very small group of people.
"For such a significant clerical error to happen with such a small group when there is a special process in place, that is the thing that really worries me about the confidence in the wider system."
'For such a significant clerical error to happen with such a small group when there is a special process in place, that is the thing that really worries me about the confidence in the wider system.'Jenny Marra.
Mr Harra said he shares such concerns, but added he is "satisfied" the issue would not have applied to the general population.
He said: "There is a special clerical process that applies to parliamentarians and that is what went wrong.
"The process for the main bulk of the population is an automated one, based on the address."
However, he also told the committee HMRC had to correct some 30,000 self-assessment tax returns after people failed to identify themselves as Scottish taxpayers.
"The error rate is too high," he conceded.
A tick box was included in the form for people to say if they are a Scottish taxpayer.
The change was made after the Scottish Government determined higher earners - such as MSPs - should pay more in income tax than those on the same salary south of the border, while low-paid workers pay less than their counterparts in England.
HMRC had initially based its calculations on what people put on the form, but Mr Harra said: "We quickly learned the level of error in returns was such that it was actually better to calculate the level of tax based on what we knew from our own database.
"The entries on the self-assessment tax returns, our experience is they are not the best indicator of whether someone is a Scottish taxpayer because the error rate in them is higher than they would like.
"We are going to have to continue improving the accuracy of what taxpayers put on those returns and in the meantime we have taken the decision not to rely on what people put on those returns."