I participated in a local, FIDE-rated tournament. In its first round,
the chief arbiter paired the players 4 times
This has happened to me too, although not as many as 3 repairings that I am aware. As an arbiter I've also done repairing in the first round although only ever in small local events. I would try very, very hard indeed to avoid doing this in a norm event. Normal procedure for the first round in a norm event to avoid this happening is to require the players to register their presence before a certain time and do the pairings when this time is reached. Any player who doesn't register in time is excluded from the first round.
There is a unique problem in the first round of a tournament in that usually it is possible as a player to ask for and be granted a half point bye and players will often choose to miss the first round. This information goes to the organiser who should pass it on to the arbiter but often some of this information "goes astray". With luck this is discovered before the round starts. In that case the correct procedure is to redo the pairings taking into account the updated bye information.
Sometimes this information isn't discovered until the round has started. In this case some players will have sat there with no opponent because the opponent requested a bye but that information got lost. They will be awarded the full point. When you look at the pairings the next day you will see that these players are shown not having an opponent in round one (even though when the round was played they did) but each getting one full point instead of the half point they would get for a bye. Any time you see more than one player get a full point bye you know this is what happened.
The organiser and arbiter can try and be strict and say byes must be agreed the day before but then half an hour before the first round is due to start a player rings up to say that there has been an accident on the motorway, he is going to be delayed and won't arrive in time to play his game, can he have a half point bye?
When this happens, again, the arbiter should repair using the new information. This can be annoying but it is real life.
Now modify the scenario slightly. This time the round has started but it is still before the default time and again a player phones up. He is giving a lift to another player and again they will miss the round because of an accident. They are not paired against each other so two players are sitting at their boards without opponents. As the arbiter, what is the best thing to do? As long as the organiser wrote in the tournament conditions that in this situation the players can be repaired then the correct thing is to repair the two players without opponents. The only way to do this is manually. If the two players without opponents are seeded 2 and 3 then the pairings will be changed so that 2 plays 3 and the two missing players who may be 56 and 57 each end up getting a half point bye.
How do I know? - I've made a script in Perl to calculate the pairings
for the first round in a Swiss-system, but the output is different
from the reality
I'm an FA so I don't need to write a Perl script to check the pairings but as a player I have several times looked at the results from the previous round and calculated who I should be playing in the next round because the pairings are slow coming out. On one occasion the published pairings agreed with my calculations but were changed the next morning when I came to play and on several others they did not correspond. I ended up paired against somebody completely different! It has also happened to me in large, prestigious events where I do not expect such things to happen. How could this be?
Well, it is actually very simple. Take a very large tournament in a very small place with few local players like Iceland or Isle of Man. Most of the local players will be entered. This is their big chance to play new people without having to travel. With all these other players from distant and often exotic locations they really don't want to miss out and play their clubmate who they play several times a year, if not month.
If it is not a high level tournament like a norm event then it is reasonable to approach the arbiter (ideally before the event starts) and say "I don't want to play other islanders. Please don't pair me against them". This is reasonable and understandable and in every case where the pairings don't match my calculations I have found that such a thing explains the difference.
In the case where the pairings were changed on me I suspect that an initial error was made and a "forbidden pairing" which had been requested hadn't been entered correctly and players who had requested not to be paired against each other had this happen, noticed and then asked the arbiter to correct this.
Is it possible to know if they "cheated" from the .TUNX Swiss-Manager
file and possibly report this case to the national chess federation?
In the case of a norm event then, yes, it should be possible and was done for the big Gibraltar tournament a few years ago when Hou Yifan complained that she was paired against too many women. (Spoiler alert: she was wrong) However for smaller tournaments this is not really possible unless you have all the information including bye requests, late bye requests, missed bye requests and requested forbidden pairings.
As an aside I did play in a tournament a few years ago where they openly cheated on the pairings and the prizes! They even announced before the first round that they were going to do this. It wasn't FIDE rated and it wasn't nationally graded and all I could do was complain to them loudly and vow never to play in one of their tournaments again.