Why does competition work for capitalism? As far as I know, capitalism is based on competition: 
If two(or more) companies produce similar products that compete against other, these companies are in a competition.
Because the objective of a company is to earn as much money as possible, the company will try to maximise the selling of their product. However, because normally there are more than a single company, every company has to sell their best possible product for the lowest price without making enough profit. That leads to a situation where the consumer gets a very good product for a very fair-realistic price.

My problem here is, that this only works if every company only can make the decision about what price they make for what quality once. Like in the prisoner's dilemma.
The prisoner (the company) will (usually; if he is sane) make the decision to betray his member (->Game Theory).
The point is the ideal strategy changes if this 'game' will be repeated forever (is identical to a situation where nobody knows, when the game ends). The strategy any sane prisoner would take is to not betray his gang-member, however, if his member betrays him he will betray him, too, until his member does not betray him anymore.
Because this is a simplified version of a real competition, real companies should act like the prisoners: make a high price until the competitor make a low price. However, no company would make a low price because although they would make better profit in short term, the company would make better in longterm if they made the unspoken deal with the other companies.

So why is it not like this in real world, or is it like this and I haven't noticed that yet?
When two companies produce commodities and/or services that are substitutes then they are simply producing for a market that allows the presence of two or more substitutes.


  "...If two (or more) companies produce similar products that compete against other, these companies are in a competition"


Two firms do not necessarily compete with each other when they are supplying substitutes in the market. 

What needs to be clear is that qualifying a market as competitive amounts to making a series of statements about the way the participants in the market behave, their numbers, how potential new participants can interact with the market, the relevant time scale etc. 

Narrowing the focus on two members of a market and claiming that they are in competition is not warranted by the assumptions. Nothing has been said about the structure of the market they are embedded in. They could eg be simply trying to flood the market with alternatives to a third commodity so as to narrow the market share of a third producer; the possibilities are really unbounded.


  "...Because the objective of a company is to earn as much money as possible, the company will try to maximise the selling of their product."


The objectives of firms are really as diverse as is the number of industries and producers immense. "Making money" is not always a single operative constraint. Firms have a plurality of goals and obtaining liquidity is one of them. How binding that goal is depends on a host of issues like the market they are embedded in, the firm's size and relative position in the market, probably its access on financing etc.

Profit maximization is an assumption about the behavior of firms which is historically relevant and analytically useful but it is not always the case that firms are maximizing profits. They may be going for market share, or they may be simply optimizing some other metric. And, of course it could very well be the case that they are just winging it!


  "...However, because normally there are more than a single company, every company has to sell their best possible product for the lowest price without making enough profit..."


Again, this claim is not universally true. The number of firms in the market is not always a guarantee of 'quality' and 'affordability'. What matters is the cost structure of the industry, the technology and the assumptions about the market structure. Also, profits that vanish to zero is, again, a feature of the competitive model; not what 'really' obtains.

Now, as far as the 'Prisoner's dilemma' is concerned: In an one-shot game the best thing to do is to 'defect'. In a repetitive setting, that is also open-ended (no predetermined end date) I think that anything goes. You would have to make more assumptions about the number of players and their strategies over time (and in response to others') in order to arrive at definitive conclusions. 

The short and non-definitive answer to the question of why don't firms collude when involved into price-competition with each other would be that there are laws that prevent them from that ie the fundamental cost structure of the game is different than what the 'dilemma' posits.