Use an array version of TEXTJOIN()
=TEXTJOIN(",",TRUE,IF(B2:E2="x",$B$1:$E1,""))
Being an array formula it needs to be confirmed with Ctrl-Shift-enter instead of Enter when exiting edit mode.
You can also use helper columns. In H2 put:
=IF(B2="X","," &B$1,"")
Drag over 4 columns and down the length of the data.
Then in F2 put:
=MID(H2&I2&J2&K2,2,99)
The other option is a long formula that combines the two steps above:
=MID(IF(B2="X","," &B$1,"")&IF(C2="X","," &C$1,"")&IF(D2="X","," &D$1,"")&IF(E2="X","," &E$1,""),2,99)