title: How do I stop the program from overwritting existing text file
body: <p>I am making a game in which 2 players roll 2 dice 5 times and then the scores are saved in a file and after the game top 5 scores from the saved scores are printed.
  I am trying to print the top 5 scores but my program would clear everything in the existing file and would only print the scores from the game just played.</p>
  <pre><code>file = open(&quot;Leaderboard.txt&quot;,'w')
  file.write(&quot;Name        &quot; + &quot;Score&quot; + &quot;\n&quot;) #Heading
  file.close()
  
  file = open(&quot;Leaderboard.txt&quot;,'a')
  file.write((player1) + &quot;:&quot; + (str(score1)) + &quot;\n&quot;) #Stores Player 1's Name and Score
  file.write((player2) + &quot;:&quot; + (str(score2)) + &quot;\n&quot;) #Stores Player 2's Name and Score
  file.close()
   
   
  file = open(&quot;Leaderboard.txt&quot;,'r')
  readthefile = file.readlines()
  sortedData = sorted(readthefile, reverse = True)  #Sorting the Data
  
  
  print(' ')
  print(&quot;==============================&quot;)
  print(&quot;    Top 5 Winning Scores&quot;)
  print(' ')
  
  for line in range (5):  #Outputs the Top 5 Players
      print(str(line + 1) + &quot;\t&quot; + str(sortedData[line]))
  </code></pre>
  <p>This is what it prints</p>
  <pre><code>==============================
      Top 5 Winning Scores
   
  1   vedant:43
  2   saiyen:37
  3   Name        Score
  </code></pre>
  <p>It will only print the scores from this game and won't from the previous games. The error I am getting is IndexError: list index out of range</p>
  <p>Help would be much appreciated!</p>