The power dissipated by the LM338 is Vin - Vout times the current times the duty cycle. Vin - Vout = 12.4 V I = 24.8 W. Your duty cycle is 5/35 ~ 14% . Because the transistor is on for 5 seconds, it would get to its final temperature in this time. If this unit is going to be at different voltages, then sample calculations must be done to find out what the maximum point of dissipation.
From :-
https://www.ti.com/lit/ds/symlink/lm338.pdf, max junction temp = 125 deg C, Tr j-c = 4 degsC/W, Tr j-a = 50 degsC /W. What about if the heater gets left on? either design the heat sink to carry the whole power or put a thermostat on the heatsink/thermal trip to trip the power if the heat sink gets too hot. So whats your ambien temperature - air conditioned lab = 20 degs C, industrial area or electronic cabinet = 40 degs C. At a power of 25 W the case drops 25 X 4 degrees from the junction, so now the maximum case temperature can only be 125 - 100 = 25 degsC. So at a continous dissipation the LM338 needs its case to be kept to less then 25 degs C !!! This is a bad design, get rid off some of the excess input voltage by putting a resistor in series, 8 ohms would halve the dissipation in the regulator , needs to be > 16W rating. The LM388, now has to drop 4V at 2 A, i.e. 8W, so its case now has a thermal drop from the junction of 4 X 8 = 32 degsC. So the its case can now be at 125 - 32 = 93 degs C. Given an ambient temperature of 40 degsC, then the heatsink has to get rid of 93-40 = 53 degsC at a power of 8W or 6 degs/W ,like :-
https://uk.farnell.com/fischer-elektronik/fk-201sa-3/heat-sink-to-3-6-c-w/dp/4621359, this is for TO-3, you need TO 220.
Frank