In these films, it is depicted that Peter and his shadow can be separated. Although the same person, Peter and his shadow can be considered as separate bodies. Like how in some films, when a hand gets separated from the body, it continues to act independently. Or when someone is beheaded, their body tries to find the head back.
Peter Pan got separated from his shadow as depicted in the two films -
In the film, while Peter was visiting the Darling household to listen to stories, the Darling's dog Nana barked at the intruders and while Peter escaped, his shadow was captured. That night, Wendy Darling discovered the shadow and stored it in her draw to prevent it from getting into trouble. The next night, Peter and Tinker Bell returned to retrieve it. When they found it, they accidentally woke Wendy. As Peter attempted to restore it with soap, Wendy preferred the proper way and sewed it back. - Peter Pan (1953)
...that night, Wendy catches a glimpse of Peter hovering over her bed that night and her nursemaid and dog Nana steals his shadow just as he escapes. Wendy is caught drawing Peter in her book in school the next morning. While chasing the delivery boy carrying a letter from Wendy's teacher to Mr. Darling at the bank, Wendy and Nana literally crash into him and spoil his chances of impressing his superiors. Mr. Darling chains Nana outside and reprimands Wendy before he, Mrs. Darling leave for a party, leaving the children with Aunt Millicent. Peter visits Wendy again, who sews his shadow back on. - Peter Pan (2003)
Hence it seems that his shadow and him both have a playful personality. While it was sewed back up again, the shadow may continue to play with Peter Pan by being separated and teasing him. Though after being sewed back up, the shadow is now a part of Peter.