After you leave Hong Kong there is no reason to keep it ( from the HK authority point of view )
There are some cases, or personal reasons why you would want to keep it thought.
In fact I personally do not like the fact that passport stamps are abolished.
A personal experience I had with such a case was the need to show evidence from to 3rd-party country that I indeed exited that country and entered HK( due to a bureaucratic mess ).
In that case this little "slip" actually saved the situation - and I am since keeping ALL of the slips I get from each country I visit .
Another example would be ( in some cases ) where you would want to apply for a permanent resident visa to HK ( while outside HK ), or when need to prove the "right of adobe" - that slip is not mandatory but can help in explaining some situations.
This slip is just an "evidence" of your entry, and in fact, the HK authorities do not even need it - it is all documented digitally and you can even get copies of all slips at any immigration point - and also at the immigration tower in wan chai.
Also, regarding the case you have just mentioned of the Chinese immigration - this happened to me once in Macau also ( going by ferry from HK ) and in fact, also ARRIVING in HK I was asked for the MACAU slip. do I guess it works both ways.
On a side note :
There is also a "legal" issue to what is the exact meaning of
right after I leave Hong Kong
Does passing immigration without still entering a third country qualifies as 100% "leaving" ?