in reply to slighly newbish question

You

  1. slurp the file into a single scalar,
  2. remove all the newlines,
  3. split that string on colons,
  4. keep the last 20 fields,
  5. rejoin them with colons,
  6. and write that single string to a file without any newline.
I'm a little confused by your use of 'lines' in the comments and description.

Would local $/ = ':'; simplify your program? I don't think your problem is with splice. Look for differences from what you expect in the script-written messages.txt.

You ought to see about doing this with messages.txt opened '+<' and flocked.

After Compline,
Zaxo