No problem with "redundant"... we are always happy to help
So,
Budapest-Krakow: simplest and cheapest option is to buy discounted Budapest-Krakow ticket for the overnight connection (from 39 euro for 6 berth couchette or 45 for 3 bed sleeper). But those are sold in limited numbers + you need to buy them at least 3 days in advance. As you can see, this option is only good if you plan to spend some time in Budapest. Standard one way fare is kind of high - 75 euro, and it's only for the seat, so you would need additional 10-14 euro for sleeper supplement.
In case you are ready for some savings, then you can consider couple options: board domestic Budapest-Esztergom train (1100 HUF or around 4 euro), Esztergom is a nice town+ it's located just across the river from Slovak town Sturovo (check google maps). In Slovakia you can get a better deal on tickets, since you can buy two separate ones for two legs of the same journey. One is from Sturovo till Bohumin (last Czech station before Poland) - around 23 euro, other from Bohumin till Krakow (15 euro). Then just board the train and show conductor both tickets. As result you'll pay less than 45 euro instead of 75. If you prefer day time trips, then you might go directly from Slovakia to Poland via Skalite-Swardon, it will be quite cheap, but will take the whole day long.
Fully different option is bus, Eurolines runs quite cheap bus from Budapest to Krakow (
http://www.volanbusz.hu/en/, from 3900 HUF), but only twice a week.
Krakow-Wroclav: multiple trains on the route (
http://rozklad-pkp.pl/), cheapest are InterRegio (only 39 PLN), TLK trains are 48PLN.
Wroclav-Prague: Though the distance between two aren't that big, but actually it is quite difficult to do the trip by train - at least two changes of train. Standard international fare is around 27 euro, but you can cut it if you buy domestic Polish ticket till the border (town Miedzylesie) + domestic Czech from the border (town Lichkov) to Prague.
Prague-Berlin: easy, multiple trains and good choice of discounted tickets - just buy one some time in advance here -
https://www.cd.cz/eshop/ (from 29 euro)
Feel free to ask additional question... in case you have any