I'm guessing your algorithm works on the assumption that each line in file1 corresponds to that same line in file 2 ..? (In other words, line 1 in file 1 should be the same item (aka: program&icon) as line 1 in file 2....)
In which case, you could simply perform a string check against each line of file 2 to make sure that they end with the "[filename]" (minus the ".exe" and replace with ".png"), and only remove that line (or rather, exclude it from being re-written) if it matches the item you want to delete.
So for example...
String itemYouWishToDelete = "item.exe"; // <-- What ever you've clicked on...
File file2 = new File("file2.txt");
Scanner scanner = new Scanner(file2);
while (scanner.hasNextLine()){
String line = scanner.nextLine();
if (line.endsWith(itemYouWishToDelete.replace(".exe",".png"))) {
// delete the item
}
}