[SPARK-3948][Shuffle]Fix stream corruption bug in sort-based shuffle

Kernel 2.6.32 bug will lead to unexpected behavior of transferTo in copyStream, and this will corrupt the shuffle output file in sort-based shuffle, which will somehow introduce PARSING_ERROR(2), deserialization error or offset out of range. Here fix this by adding append flag, also add some position checking code. Details can be seen in [SPARK-3948](https://issues.apache.org/jira/browse/SPARK-3948).
This `assert` checks whether `finalPos` is `initialPos + size`, but this error message uses `initialPos + count`; could this lead to confusion?

I suppose that `count >= size` here, so it's probably fine, but it might be confusing if `count` was ever greater than `size`.