In F2 enter the array formula:
=TEXTJOIN(",",TRUE,IF(B2:E2="X",$B$1:$E$1,""))
and copy down:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.