Titles like "Emperor" historically held a lot of prestige, and not very many people ever held them. Was there something preventing rulers from just declaring themselves Emperor that led to this relative rarity?

by Arondeus

To my understanding, it was generally agreed that a Duke was better than a Baron, a King was better than a Duke, and an Emperor was better than a King.

If one title is better than another, what would prevent a sovereign ruler from just "upgrading"? Polities did change the title of their rulers sometimes, such as the Duke of Bohemia becoming the King of Bohemia at some point in the middle ages.

What would have happened if some Duke in a tiny independent region suddenly started calling himself King, or Emperor? What would the reactions have been from their neighbors, and did this ever happen historically?

Temponautics

The history of ruling titles is itself steeped deeply into history, and at that into individual local history. It is one thing to abstract the titles into a seeming system ("A king is a king"), when the reality does not actually reflect that -- noble titles were not standardized in any sense of the word, and must each be seen in their context.
The title of a king, for instance, mostly suggests the highest position in a given power system, mostly of a European tribal background or alliance (the etymology of the word "king" is still not satisfactorily explained). A "Duke", as a title, from the Latin ducere - to lead - actually stems from a title for a general, i.e. someone who leads in service of another. (In German, a Duke is a Herzog, someone who leads a Heerzug, an army). Lower titles (as they came to be perceived, i.e. Margrave/Marquis, Baron, Graf, Count, etc) were similarly considered local leaders subservient to a higher power, but always in a specific context.
Claiming a higher title then comes with a certain political danger: that you are perceiving yourself as a more sovereign leader, and that therefore an annexation of your position and title comes with that power, too. In this regard, it is noteworthy that the Dukes of Prussia, when choosing to be Kings, were careful to first choose the title King in Prussia (and not of Prussia) to signify that they were absolute rulers inside the lands of Prussia, but not outside, and therefore were making no claims whatsoever within their given power structure to the title King of the Germans, which was still in existence in 1700 and which rested with the Habsburg Emperor. (Most of Prussia was outside the Holy Roman Empire, and therefore theoretically not under the aegis of the German King, but the Prussian rulers needed to signal that they still considered themselves Germans within the power logic of the HRE.)
And this example shows that each noble title and position was steeped in its own complicated political settings. (Hence the British granted Napoleon after his first defeat and exile the title of Emperor of Elba, more of a mockery on him than anything else, but it also avoided a downgrading of the formal title).
In short (and to oversimplify as much as a short answer allows), simply declaring a title came in most contexts with a simply unaffordable political price tag, which explains why it didn't happen very often.

Dongzhou3kingdoms

u/Temponautics gave a good answer. I did an answer on what is to stop a King just becoming Emperor or giving themselves whatever title they wanted which touches on some of the issues. I have an example from my era, an act of spectacular folly from a powerful warlord, but it seems like your looking for European examples