Please provide the createhlsstream parameters you used. You need to set playlistType=rolling to limit the segment files created to the playlistLength setting (10 by default) plus the staleRetentionCount setting (same as playlistLength by default). Note that playlistType=appending by default. The playlistLength and staleRetentionCount parameters are disregarded when playlistType=appending.
For details, please refer to the createhlsstream command in the API Definition Guide document. The description and default value of each parameter is described there. You can also refer to the Media Server User Guide for some examples.