Why is ON DUPLICATE KEY not working as expected?
Any idea why this query doesn't work with table B? Do you have to insert/update every table column when running the query? 


Yes, UserName is a NOT NULL column and doesn't have a DEFAULT value. Therefore you need to provide a value for every row INSERT. Not for UPDATE though, the column can be updated or not, depending on your requirements.


  Is it a PHP settings I need to change on my hosting?


No, nothing to do with PHP.


  I had a script which worked perfectly fine on my old hosting ...


If the script was working perfectly in the previous server, when inserting in either table, then the tables were not transferred identically. The extra columns - besides the 3 that the script provides values for - would have been defined as NULL (so they'd have a DEFAULT NULL) or there might be a DEFAULT attribute defined when the table was created.

Another possibility - besides lack of DEFAULT attribute - is that the table had an INSERT trigger that supplied a value for the UserName automatically upon insert and that the triggers were not properly copied when the the database was transfered.