[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).
Should we change this default to `false`?  This would help us to guard against cases in which new code uses `copyStream` on File[Input|Output]Streams but the programmer forgot to read the configuration option.  I guess my concern is that I want to ensure that if `spark.file.transferTo` is false, then we are guaranteed to _never_ use the `transferTo` path in this function.