HTML rendering merges multiple spaces into a single space unless you make them an non-breaking space. If you want the space to be retained when there are multiple consecutive spaces then your replace code should use:
Note several Calibre features delete most non-breaking spaces (like Heuristics), so it's still not a guarantee that it will still be there at the end, it depends on the conversion settings.